home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Source Code / VirtualDub / vdicmdrv / CCompRemote.cpp next >
C/C++ Source or Header  |  2003-10-01  |  11KB  |  334 lines

  1. #include <crtdbg.h>
  2.  
  3. #include "resource.h"
  4. #include "vdserver.h"
  5.  
  6. #include "CCompRemote.h"
  7.  
  8. extern HINSTANCE g_hInst;
  9.  
  10. static HINSTANCE g_hInstVDSVRLNK;
  11. static FARPROC g_fpGetDubServerInterface;
  12. static IVDubServerLink *g_ivdsl;
  13.  
  14. CCompRemoteDriver videoDriverRemote;
  15.  
  16. CCompRemoteDriver::~CCompRemoteDriver() {
  17. }
  18.  
  19. BOOL CCompRemoteDriver::Load(HDRVR hDriver) {
  20.     if (g_hInstVDSVRLNK = LoadLibrary("vdsvrlnk.dll")) {
  21.         if (g_fpGetDubServerInterface = GetProcAddress(g_hInstVDSVRLNK, "GetDubServerInterface")) {
  22.             g_ivdsl = ((IVDubServerLink *(__cdecl *)())g_fpGetDubServerInterface)();
  23.  
  24.             return TRUE;
  25.         }
  26.         FreeLibrary(g_hInstVDSVRLNK);
  27.         g_hInstVDSVRLNK = NULL;
  28.     }
  29.     return FALSE;
  30. }
  31.  
  32. void CCompRemoteDriver::Free(HDRVR hDriver) {
  33.     if (g_hInstVDSVRLNK) {
  34.         FreeLibrary(g_hInstVDSVRLNK);
  35.         g_hInstVDSVRLNK = NULL;
  36.     }
  37. }
  38.  
  39. DWORD CCompRemoteDriver::Open(HDRVR hDriver, char *szDescription, LPVIDEO_OPEN_PARMS lpVideoOpenParms) {
  40.     return (DWORD)new CCompRemote();
  41. }
  42.  
  43. void CCompRemoteDriver::Disable(HDRVR hDriver) {
  44. }
  45.  
  46. void CCompRemoteDriver::Enable(HDRVR hDriver) {
  47. }
  48.  
  49. LPARAM CCompRemoteDriver::Default(DWORD dwDriverID, HDRVR hDriver, UINT uiMessage, LPARAM lParam1, LPARAM lParam2) {
  50.     return DefDriverProc(dwDriverID, hDriver, uiMessage, lParam1, lParam2);
  51. }
  52.  
  53. /////////////////////////////////////////////////////////////
  54.  
  55. CCompRemote::CCompRemote() {
  56.     ivdac = NULL;
  57. }
  58.  
  59. CCompRemote::~CCompRemote() {
  60.     if (ivdac) g_ivdsl->FrameServerDisconnect(ivdac);
  61. }
  62.  
  63. BOOL CCompRemote::AboutProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
  64.     switch(msg) {
  65.         case WM_COMMAND:
  66.             if (LOWORD(lParam) == IDCANCEL) {
  67.                 EndDialog(hDlg, 0);
  68.                 return TRUE;
  69.             }
  70.             break;
  71.     }
  72.     return FALSE;
  73. }
  74.  
  75. LRESULT CCompRemote::About(HWND hwnd) {
  76.     if (hwnd != (HWND)-1L) {
  77.         DialogBox(g_hInst, MAKEINTRESOURCE(IDD_ABOUT), hwnd, (DLGPROC)CCompRemote::AboutProc);
  78.     }
  79.  
  80.     return ICERR_OK;
  81. }
  82.  
  83. LRESULT CCompRemote::Compress(ICCOMPRESS *icc, DWORD cbSize) {
  84.     return ICERR_UNSUPPORTED;
  85. }
  86.  
  87. LRESULT CCompRemote::CompressFramesInfo(ICCOMPRESSFRAMES *icf, DWORD cbSize) {
  88.     return ICERR_UNSUPPORTED;
  89. }
  90.  
  91. LRESULT CCompRemote::CompressGetFormat(BITMAPINFO *lpbiInput, BITMAPINFO *lpbiOutput) {
  92.     return ICERR_UNSUPPORTED;
  93. }
  94.  
  95. LRESULT CCompRemote::CompressGetSize(BITMAPINFO *lpbiInput, BITMAPINFO *lpbiOutput) {
  96.     return 16;
  97. }
  98.  
  99. LRESULT CCompRemote::CompressQuery(BITMAPINFO *lpbiInput, BITMAPINFO *lpbiOutput) {
  100.     return ICERR_UNSUPPORTED;
  101. }
  102.  
  103. LRESULT CCompRemote::DecompressGetFormat(BITMAPINFO *lpbiInput, BITMAPINFO *lpbiOutput) {
  104.     BITMAPINFOHEADER *bmihInput        = &lpbiInput->bmiHeader;
  105.     BITMAPINFOHEADER *bmihOutput    = &lpbiOutput->bmiHeader;
  106.     LRESULT res;
  107.  
  108.     if (!lpbiOutput)
  109.         return sizeof(BITMAPINFOHEADER);
  110.  
  111.     if (ICERR_OK != (res = DecompressQuery(lpbiInput, 0)))
  112.         return res;
  113.  
  114.     bmihOutput->biSize            = sizeof(BITMAPINFOHEADER);
  115.     bmihOutput->biWidth            = bmihInput->biWidth;
  116.     bmihOutput->biHeight        = bmihInput->biHeight;
  117.     bmihOutput->biPlanes        = 1;
  118.     bmihOutput->biBitCount        = 24;
  119.     bmihOutput->biCompression    = BI_RGB;
  120.     bmihOutput->biSizeImage        = ((bmihInput->biWidth*3+3)&-4)*bmihInput->biHeight;
  121.     bmihOutput->biXPelsPerMeter    = bmihInput->biXPelsPerMeter;
  122.     bmihOutput->biYPelsPerMeter    = bmihInput->biYPelsPerMeter;
  123.     bmihOutput->biClrUsed        = 0;
  124.     bmihOutput->biClrImportant    = 0;
  125.  
  126.     return ICERR_OK;
  127. }
  128.  
  129. static void *DibXY(BITMAPINFOHEADER *bih, void *ptr, long x, long y) {
  130.     return (void *)(
  131.             (char *)ptr
  132.             + x*(bih->biBitCount/8)
  133.             + y*4*((bih->biBitCount*bih->biWidth+31)/32)
  134.         );
  135. }
  136.  
  137. LRESULT CCompRemote::DecompressBegin(BITMAPINFO *lpbiInput, BITMAPINFO *lpbiOutput) {
  138.     LRESULT lres;
  139.     BITMAPINFOHEADER bmih;
  140.  
  141.     if (ICERR_OK != (lres = DecompressQuery(lpbiInput, lpbiOutput)))
  142.         return lres;
  143.  
  144.     if (ivdac) g_ivdsl->FrameServerDisconnect(ivdac);
  145.  
  146.     _RPT0(0,"Attempting to connect to frameserver...\n");
  147.  
  148.     ivdac = g_ivdsl->FrameServerConnect("VCM");
  149.  
  150.     if (!ivdac) return ICERR_BADFORMAT;
  151.  
  152.     _RPT0(0,"Connected.\n");
  153.  
  154.     if ((lres=ivdac->readFormat(&bmih, FALSE))<0 || bmih.biWidth != lpbiOutput->bmiHeader.biWidth || bmih.biHeight != lpbiOutput->bmiHeader.biHeight) {
  155.  
  156.         if (lres) _RPT1(0,"Failed to read format (%d)\n", lres);
  157.         else _RPT4(0,"Formats not same: %dx%d vs. %dx%d\n",
  158.             bmih.biWidth,
  159.             bmih.biHeight,
  160.             lpbiOutput->bmiHeader.biWidth,
  161.             lpbiOutput->bmiHeader.biHeight
  162.             );
  163.  
  164.         g_ivdsl->FrameServerDisconnect(ivdac);
  165.         ivdac = NULL;
  166.         return ICERR_BADFORMAT;
  167.     }
  168.  
  169.     dwWidth        = bmih.biWidth;
  170.     dwHeight    = bmih.biHeight;
  171.  
  172.     return ICERR_OK;
  173. }
  174.  
  175. LRESULT CCompRemote::DecompressEnd() {
  176.     if (ivdac) {
  177.         g_ivdsl->FrameServerDisconnect(ivdac);
  178.         ivdac = NULL;
  179.     }
  180.  
  181.     return ICERR_OK;
  182. }
  183.  
  184. LRESULT CCompRemote::DecompressExBegin(ICDECOMPRESSEX *icdex, DWORD cbSize) {
  185.     return DecompressBegin((BITMAPINFO *)icdex->lpbiSrc, (BITMAPINFO *)icdex->lpbiDst);
  186. }
  187.  
  188. LRESULT CCompRemote::DecompressExEnd() {
  189.     return DecompressEnd();
  190. }
  191.  
  192. LRESULT CCompRemote::DecompressEx(ICDECOMPRESSEX *icdex, DWORD cbSize) {
  193.     BITMAPINFOHEADER *bmihInput        = icdex->lpbiSrc;
  194.     BITMAPINFOHEADER *bmihOutput    = icdex->lpbiDst;
  195.     LRESULT res;
  196.     long w0s, h0s, w0d, h0d;
  197.  
  198.     /////////////////////
  199.  
  200. #if 0
  201.     _RPT1(0,"\tdwFlags: %p\n",icdex->dwFlags);
  202.     _RPT1(0,"\tlpbiSrc: %p\n",icdex->lpbiSrc);
  203.     _RPT1(0,"\t\tbiSize:          %ld\n", icdex->lpbiSrc->biSize);
  204.     _RPT1(0,"\t\tbiWidth:         %ld\n", icdex->lpbiSrc->biWidth);
  205.     _RPT1(0,"\t\tbiHeight:        %ld\n", icdex->lpbiSrc->biHeight);
  206.     _RPT1(0,"\t\tbiPlanes:        %ld\n", icdex->lpbiSrc->biPlanes);
  207.     _RPT1(0,"\t\tbiBitCount:      %ld\n", icdex->lpbiSrc->biBitCount);
  208.     _RPT1(0,"\t\tbiCompression:   %ld\n", icdex->lpbiSrc->biCompression);
  209.     _RPT1(0,"\t\tbiSizeImage:     %ld\n", icdex->lpbiSrc->biSizeImage);
  210.     _RPT1(0,"\t\tbiXPelsPerMeter: %ld\n", icdex->lpbiSrc->biXPelsPerMeter);
  211.     _RPT1(0,"\t\tbiYPelsPerMeter: %ld\n", icdex->lpbiSrc->biYPelsPerMeter);
  212.     _RPT1(0,"\t\tbiClrUsed:       %ld\n", icdex->lpbiSrc->biClrUsed);
  213.     _RPT1(0,"\t\tbiClrImportant:  %ld\n", icdex->lpbiSrc->biClrImportant);
  214.     _RPT1(0,"\tlpSrc:   %p\n",icdex->lpSrc);
  215.     _RPT1(0,"\tlpbiDst: %p\n",icdex->lpbiDst);
  216.     _RPT1(0,"\t\tbiSize:          %ld\n", icdex->lpbiDst->biSize);
  217.     _RPT1(0,"\t\tbiWidth:         %ld\n", icdex->lpbiDst->biWidth);
  218.     _RPT1(0,"\t\tbiHeight:        %ld\n", icdex->lpbiDst->biHeight);
  219.     _RPT1(0,"\t\tbiPlanes:        %ld\n", icdex->lpbiDst->biPlanes);
  220.     _RPT1(0,"\t\tbiBitCount:      %ld\n", icdex->lpbiDst->biBitCount);
  221.     _RPT1(0,"\t\tbiCompression:   %ld\n", icdex->lpbiDst->biCompression);
  222.     _RPT1(0,"\t\tbiSizeImage:     %ld\n", icdex->lpbiDst->biSizeImage);
  223.     _RPT1(0,"\t\tbiXPelsPerMeter: %ld\n", icdex->lpbiDst->biXPelsPerMeter);
  224.     _RPT1(0,"\t\tbiYPelsPerMeter: %ld\n", icdex->lpbiDst->biYPelsPerMeter);
  225.     _RPT1(0,"\t\tbiClrUsed:       %ld\n", icdex->lpbiDst->biClrUsed);
  226.     _RPT1(0,"\t\tbiClrImportant:  %ld\n", icdex->lpbiDst->biClrImportant);
  227.     _RPT1(0,"\tlpDst:   %p\n",icdex->lpDst);
  228.     _RPT4(0,"\tSource:  (%d,%d), size %dx%d\n", icdex->xSrc, icdex->ySrc, icdex->dxSrc, icdex->dySrc);
  229.     _RPT4(0,"\tDest:    (%d,%d), size %dx%d\n", icdex->xDst, icdex->yDst, icdex->dxDst, icdex->dyDst);
  230.     return ICERR_OK;
  231. #endif
  232.  
  233.     /////////////////////
  234.  
  235.     if (!ivdac) {
  236.         if (ICERR_OK != (res = DecompressExBegin(icdex, cbSize)))
  237.             return res;
  238.     } else {
  239.         if (ICERR_OK != (res = DecompressExQuery(icdex, cbSize)))
  240.             return res;
  241.     }
  242.  
  243.     if (icdex->dwFlags & (ICDECOMPRESS_UPDATE))
  244.         return ICERR_BADPARAM;
  245.  
  246.     w0s = icdex->dxSrc==-1 ? bmihInput->biWidth  : icdex->dxSrc;
  247.     h0s = icdex->dySrc==-1 ? bmihInput->biHeight : icdex->dySrc;
  248.     w0d = icdex->dxDst==-1 ? bmihOutput->biWidth  : icdex->dxDst;
  249.     h0d = icdex->dyDst==-1 ? bmihOutput->biHeight : icdex->dyDst;
  250.  
  251.     if (w0s != w0d || h0s != h0d)
  252.         return ICERR_BADPARAM;
  253.  
  254.     if (w0s != bmihInput->biWidth || h0s != bmihInput->biHeight)
  255.         return ICERR_BADPARAM;
  256.  
  257.     if (icdex->xSrc != 0 || icdex->ySrc != 0)
  258.         return ICERR_OK;
  259.  
  260.     if (icdex->xDst != 0 || icdex->yDst != 0)
  261.         return ICERR_OK;
  262.  
  263.     if (VDSRVERR_OK != ivdac->readVideo(*(long *)icdex->lpSrc, icdex->lpDst))
  264.         return ICERR_ERROR;
  265.  
  266.     return ICERR_OK;
  267. }
  268.  
  269. LRESULT CCompRemote::DecompressExQuery(ICDECOMPRESSEX *icdex, DWORD cbSize) {
  270.     BITMAPINFOHEADER *bmihInput        = icdex->lpbiSrc;
  271.  
  272. #if 1
  273.     _RPT1(0,"\tlpbiSrc: %p\n",icdex->lpbiSrc);
  274.     _RPT1(0,"\t\tbiSize:          %ld\n", icdex->lpbiSrc->biSize);
  275.     _RPT1(0,"\t\tbiWidth:         %ld\n", icdex->lpbiSrc->biWidth);
  276.     _RPT1(0,"\t\tbiHeight:        %ld\n", icdex->lpbiSrc->biHeight);
  277.     _RPT1(0,"\t\tbiPlanes:        %ld\n", icdex->lpbiSrc->biPlanes);
  278.     _RPT1(0,"\t\tbiBitCount:      %ld\n", icdex->lpbiSrc->biBitCount);
  279.     _RPT1(0,"\t\tbiCompression:   %ld\n", icdex->lpbiSrc->biCompression);
  280.     _RPT1(0,"\t\tbiSizeImage:     %ld\n", icdex->lpbiSrc->biSizeImage);
  281.     _RPT1(0,"\t\tbiXPelsPerMeter: %ld\n", icdex->lpbiSrc->biXPelsPerMeter);
  282.     _RPT1(0,"\t\tbiYPelsPerMeter: %ld\n", icdex->lpbiSrc->biYPelsPerMeter);
  283.     _RPT1(0,"\t\tbiClrUsed:       %ld\n", icdex->lpbiSrc->biClrUsed);
  284.     _RPT1(0,"\t\tbiClrImportant:  %ld\n", icdex->lpbiSrc->biClrImportant);
  285. #endif
  286.  
  287.     if (bmihInput->biCompression != 'TSDV') return ICERR_BADFORMAT;
  288.  
  289.     if (icdex->lpbiDst) {
  290.         BITMAPINFOHEADER *bmihOutput    = icdex->lpbiDst;
  291.  
  292. #if 1
  293.         _RPT1(0,"\tlpbiDst: %p\n",icdex->lpbiDst);
  294.         _RPT1(0,"\t\tbiSize:          %ld\n", icdex->lpbiDst->biSize);
  295.         _RPT1(0,"\t\tbiWidth:         %ld\n", icdex->lpbiDst->biWidth);
  296.         _RPT1(0,"\t\tbiHeight:        %ld\n", icdex->lpbiDst->biHeight);
  297.         _RPT1(0,"\t\tbiPlanes:        %ld\n", icdex->lpbiDst->biPlanes);
  298.         _RPT1(0,"\t\tbiBitCount:      %ld\n", icdex->lpbiDst->biBitCount);
  299.         _RPT1(0,"\t\tbiCompression:   %ld\n", icdex->lpbiDst->biCompression);
  300.         _RPT1(0,"\t\tbiSizeImage:     %ld\n", icdex->lpbiDst->biSizeImage);
  301.         _RPT1(0,"\t\tbiXPelsPerMeter: %ld\n", icdex->lpbiDst->biXPelsPerMeter);
  302.         _RPT1(0,"\t\tbiYPelsPerMeter: %ld\n", icdex->lpbiDst->biYPelsPerMeter);
  303.         _RPT1(0,"\t\tbiClrUsed:       %ld\n", icdex->lpbiDst->biClrUsed);
  304.         _RPT1(0,"\t\tbiClrImportant:  %ld\n", icdex->lpbiDst->biClrImportant);
  305. #endif
  306.  
  307.         if (bmihOutput->biPlanes != 1) return ICERR_BADFORMAT;
  308.         if (bmihOutput->biCompression != BI_RGB) return ICERR_BADFORMAT;
  309.         if (bmihOutput->biBitCount != 24) return ICERR_BADFORMAT;
  310.         if (bmihOutput->biWidth != bmihInput->biWidth) return ICERR_BADFORMAT;
  311.         if (bmihOutput->biHeight != bmihInput->biHeight) return ICERR_BADFORMAT;
  312.     }
  313.  
  314.     _RPT0(0,"--------------Accepted!\n");
  315.  
  316.     return ICERR_OK;
  317. }
  318.  
  319. LRESULT CCompRemote::GetInfo(ICINFO *lpicinfo, DWORD cbSize) {
  320.     if (cbSize < sizeof(ICINFO)) return 0;
  321.  
  322.     lpicinfo->dwSize        = sizeof(ICINFO);
  323.     lpicinfo->fccType        = ICTYPE_VIDEO;
  324.     lpicinfo->fccHandler    = 'TSDV';
  325.     lpicinfo->dwFlags        = 0;
  326.     lpicinfo->dwVersion        = 1;
  327.     lpicinfo->dwVersionICM    = ICVERSION;
  328.     wcscpy(lpicinfo->szName, L"VirtualDub remote");
  329.     wcscpy(lpicinfo->szDescription, L"VirtualDub remote frameclient");
  330.  
  331.     return sizeof(ICINFO);
  332. }
  333.  
  334.